home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / FogStyleSample / Source / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.7 KB  |  185 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        EVENTS            */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <ToolUtils.h>
  11.  
  12. #include <QD3D.h>
  13.  
  14. #include "myglobals.h"
  15. #include "myevents.h"
  16. #include "mymenus.h"
  17. #include "misc.h"
  18. #include "qd3d_support.h"
  19. #include "process.h"
  20.  
  21. extern    WindowPtr                gModelWindow;
  22. extern    QD3DSetupOutputType        gModelViewInfo;
  23.  
  24. /****************************/
  25. /*    PROTOTYPES            */
  26. /****************************/
  27.  
  28. static void DoHighLevelEvent(void);
  29. static Boolean IsDAWindow(WindowPtr whichWindow);
  30. static OSErr  hasGotRequiredParams(AppleEvent *appEvent);
  31. static void    HandleMouseDown(void);
  32.  
  33.  
  34. /****************************/
  35. /*    CONSTANTS             */
  36. /****************************/
  37.  
  38.  
  39. /**********************/
  40. /*     VARIABLES      */
  41. /**********************/
  42.  
  43. EventRecord    gTheEvent;
  44.  
  45.  
  46. /******************** HANDLE EVENTS ************************/
  47.  
  48. void HandleEvents(void)
  49. {
  50. char    theChar;
  51. GrafPtr    oldPort;
  52.         
  53.     WaitNextEvent(everyEvent,&gTheEvent, 0, 0);
  54.                 
  55.     switch (gTheEvent.what)
  56.     {
  57.         case    nullEvent:
  58.                 DoModelWindowNullEvent();
  59.                 break;
  60.                 
  61.         case    mouseDown:
  62.                 HandleMouseDown();
  63.                 break;
  64.                 
  65.         case    keyDown:
  66.         case    autoKey:
  67.                 theChar    = gTheEvent.message & charCodeMask;
  68.                 if    ((gTheEvent.modifiers & cmdKey) != 0)
  69.                     HandleMenuChoice(MenuKey(theChar));
  70.                 break;
  71.                 
  72.         case    updateEvt:
  73.                 if (!IsDAWindow((WindowPtr)gTheEvent.message))
  74.                 {
  75.                     GetPort (&oldPort);
  76.                     SetPort ((WindowPtr)gTheEvent.message);
  77.                     BeginUpdate((WindowPtr)gTheEvent.message);
  78.                     DrawControls((WindowPtr)gTheEvent.message);
  79.                     
  80.                     if ((WindowPtr)gTheEvent.message == gModelWindow)
  81.                         DrawModelWindow();
  82.                                             
  83.                     EndUpdate((WindowPtr)gTheEvent.message);
  84.                     SetPort(oldPort); 
  85.                 }
  86.                 else 
  87.                 {
  88.                     BeginUpdate((WindowPtr)gTheEvent.message);
  89.                     EndUpdate((WindowPtr)gTheEvent.message);
  90.                 }
  91.                 break;
  92.                 
  93.         case    kHighLevelEvent:
  94.                 DoHighLevelEvent();
  95.                 break;
  96.     }
  97. }
  98.  
  99.  
  100. /**************** DO HIGH LEVEL EVENT *****************/
  101.  
  102. static void DoHighLevelEvent(void)
  103. {
  104. OSErr    myErr;
  105.  
  106.     myErr = AEProcessAppleEvent(&gTheEvent);
  107. }
  108.  
  109.  
  110. /************** HANDLE MOUSE DOWN *******************/
  111.  
  112. static void HandleMouseDown(void)
  113. {
  114.     WindowPtr        whichWindow;
  115.     short             thePart;
  116.     long            menuChoice, windSize;
  117.     
  118.     thePart    =    FindWindow(gTheEvent.where, &whichWindow);
  119.     switch(thePart)
  120.     {
  121.         case    inMenuBar:
  122.                 menuChoice = MenuSelect(gTheEvent.where);
  123.                 HandleMenuChoice(menuChoice);
  124.                 break;
  125.                 
  126.         case    inSysWindow:
  127.                 SystemClick(&gTheEvent, whichWindow);
  128.                 break;
  129.                 
  130.         case    inDrag:
  131.                 DragWindow(whichWindow,gTheEvent.where, &qd.screenBits.bounds);
  132.                 break;
  133.                 
  134.         case    inGoAway:
  135.                 DisposeWindow (whichWindow);
  136.                 break;
  137.                 
  138.         case    inContent:
  139.                 SelectWindow(whichWindow);
  140.  
  141.                 break;
  142.                 
  143.         case    inGrow:
  144.                 windSize = GrowWindow(whichWindow, gTheEvent.where,
  145.                                     &(**GetGrayRgn()).rgnBBox);
  146.                 if (windSize != 0)
  147.                 {
  148.                     SetPort(whichWindow);
  149.                     EraseRect(&whichWindow->portRect);
  150.                     SizeWindow(whichWindow,LoWord(windSize),
  151.                                 HiWord(windSize), NORMAL_UPDATES);
  152.                     InvalRect(&whichWindow->portRect);
  153.                     
  154.                     if (whichWindow == gModelWindow)            // see if change Skeleton window
  155.                     {
  156.                         QD3D_ChangeDrawSize(&gModelViewInfo);
  157.                     }
  158.                 } 
  159.                 break;
  160.     }
  161. }
  162.  
  163.  
  164. /**************** IS DA WINDOW ***********************/
  165.  
  166. static Boolean IsDAWindow(WindowPtr whichWindow)
  167. {
  168.     if    (whichWindow == nil)
  169.         return (false);
  170.     else
  171.         return (((WindowPeek)whichWindow)->windowKind < 0);
  172. }
  173.  
  174.  
  175.  
  176.  
  177. /*********************** MY APPLE EVENT: QUIT APPLICATION *************************/
  178.  
  179. pascal OSErr MyAE_QuitApplication(AppleEvent *theAppleEvent, AppleEvent *reply,
  180.                             SInt32 handlerRefcon)
  181. {
  182.     CleanQuit();
  183.     return(noErr);
  184. }
  185.